package com.pig4cloud.pig.admin.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import com.pig4cloud.pig.admin.api.entity.WebIndexEntity;
import com.pig4cloud.pig.admin.api.vo.WebIndexQuery;
import com.pig4cloud.pig.admin.service.IWebIndexService;
import com.pig4cloud.pig.common.core.util.R;
import com.pig4cloud.pig.common.log.annotation.SysLog;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * 网页导航
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/web-index")
@Api(value = "webIndex", tags = "网页导航模块")
public class WebIndexController {

	@Autowired
	private IWebIndexService webIndexService;

	/**
	 * 分页查询  查
	 *
	 * @param page
	 * @param webIndexQuery
	 * @return
	 */
		@GetMapping("/page")
	public R getPage(Page page, WebIndexQuery webIndexQuery) {
		return R.ok(webIndexService.getPage(page, webIndexQuery));
	}

	//详情
	@GetMapping("/view")
	public R view(@RequestParam Integer id) {
		WebIndexEntity webIndexEntity = webIndexService.viewIndex(id);
		if (null != webIndexEntity) {
			return R.ok(webIndexEntity, "查询成功");
		}
		return R.failed("查询失败");
	}


	//新增
	@PostMapping("/add")
	public R add(@RequestBody WebIndexEntity webIndexEntity) {
		boolean success = webIndexService.add(webIndexEntity);
		if (success) {
			WebIndexEntity res = webIndexService.viewIndex(webIndexEntity.getId());
			return R.ok( res,"新增成功");
		}
		return R.failed("新增失败");
	}


	//删除
	@GetMapping("/delete")
	public R delete(@RequestParam(value = "id") Integer id) {
		boolean success = webIndexService.delete(id);
		if (success) {
			return R.ok("删除成功");
		}
		return R.failed("删除失败");
	}

	//编辑
	@PostMapping("edit")
	public R edit(@RequestBody WebIndexEntity webIndexEntity) {
		boolean success = webIndexService.edit(webIndexEntity);
		if (success) {
			WebIndexEntity res = this.webIndexService.viewIndex(webIndexEntity.getId());
			return R.ok(res,"编辑成功");
		}
		return R.failed("编辑失败");
	}

}







